<template>
  <div class="addNewBody">
    <van-nav-bar title="新增通知" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
      <div class="feedbox">
        <p class="p1">标题</p>
        <div class="feedtitle">
          <textarea name id cols="45" rows="2" placeholder="请输入标题..." v-model="feedbackTitle"></textarea>
        </div>
        <p>文本</p>
        <div class="feedtext">
          <textarea name id cols="45" rows="6" placeholder="发布信息..." v-model="feedbackDetails"></textarea>
        </div>
      </div>
      <van-button round block type="primary" native-type="submit">发布</van-button>
    </van-form>
  </div>
</template>

<script setup>
    import { ref } from "vue"
    import {newsAdd} from "../model/news"
    import { useRouter } from "vue-router"
    import { Toast } from 'vant';
        let useRoute = useRouter()
    let feedbackTitle = ref("")
    let feedbackDetails = ref("")
    const onClickLeft = () => history.back();
     
   let onSubmit = (info)=>{
    if(feedbackTitle.value&&feedbackDetails.value){
        newsAdd({
            noticeTitle:feedbackTitle.value,
            releaseStatus:feedbackDetails.value
        },{
             Authorization:window.localStorage.getItem("token")
        }).then((res)=>{
            console.log(res);
            useRoute.push("/")
        }).catch((err)=>{
            throw err
        })
  }else{
        Toast.fail('不能发布空内容');
    }
  
    }
</script>

<style lang="scss" scoped>
.feedbox {
  width: 100%;
  .p1 {
    margin-top: 20px;
  }
  p {
    width: 100%;
    height: 26px;
    font-size: 14px;
    background-color: #eeeeee;
    margin-bottom: 10px;
    line-height: 26px;
  }
  .feedtitle {
    text-align: center;
//  width:360px;
//   overflow: hidden;
  }
  .feedtext {
    text-align: center;
    // width:500px;
    //  overflow: hidden;
  }
  .van-button {
    width: 370px;
    border-radius: 10px;
    margin-left: 2px;
  }
}
.addNewBody{
    padding: 0 5px;
     box-sizing: border-box;
}
</style>